<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/validate.jsp"%>
<%@ include file="/common/operatehistory.jsp"%>
<%!
// 置顶
    List top(Integer category, Integer groupId, Integer hospital, Integer branch) {
        String selectContent = "new map(n.id as id , n.newsId as news_id, n.url as url, n.title as title, n.summary as summary, n.time as time, n.img as img, n.jsonString as json, n.tag as tag, n.category as category, n.branchName as branch_name)";
        Where where = new Where();
        if (groupId != -1) {
            where.and("t.groupId=", groupId);
        }
        if (branch != -1) {
            where.and("t.branch=", branch);
        }
        if (category != -1) {
            where.and("n.category=", category).and("t.category=", category);
        }
        List<Map> newsList = QBuilder.db("basedb").select(selectContent).from("News n, Top t").where(where.and("n.hospital=", hospital).and("n.status = ", STATUS_ENABLE).and("t.hospital=", hospital).and("t.status = ", STATUS_ENABLE).and("n.newsId = t.oid")).order("t.orderId", "asc").query().getResultObj();
        for( Map maptest : newsList){

            maptest.put("img",(List)JSON.parse(maptest.get("img").toString().replaceAll("\r","").replaceAll("\n","")));
            maptest.put("json",(Map)JSON.parse(maptest.get("json").toString().replaceAll("\r","").replaceAll("\n","")));
        }
        return newsList;
    }
%>
<%
    Integer category = input.getInt("category", 1); // 新闻类别
    Integer labelId = input.getInt("label_id", -1); // 通过标签与新闻关联查询   不传默认通过category新闻类别查
    Integer branch = input.getInt("branch", -1); // 医院分支  不传返回所有
    Integer uuid = input.getInt("uid", -1);
    List topList = top((labelId == -1 ? category : labelId), NEWS_CATEGORY, hospital, branch);
    if (topList.size() == 0) {
        msg = new Message(30041, "暂无相关数据");
        msg.put("data", new ArrayList());
        Tools.encryptPrint(out, msg);
        return;
    }
    OperateHistory oh = new OperateHistory();
    oh.setHospital(hospital);
    oh.setCategory(NEWS_CATEGORY);
    oh.setOperate(LOVE);
    msg.put("data", love(query(topList, oh), uuid, oh));
    Tools.encryptPrint(out, msg);
%>
